package com.ruoyi.webs.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateKit {
    public static boolean isContain(Date[] a, Date[] b) {
        long astatr = a[0].getTime();
        long aend = a[1].getTime();

        long bstatr = b[0].getTime();
        long bend = b[1].getTime();


        if (astatr >= bstatr && astatr <= bend) return true;


        if (astatr <= bstatr && aend >= bstatr) return true;

        return false;
    }


    public static boolean isContainEnd(Date[] a, Date[] b) {
        long astatr = a[0].getTime();
        long aend = a[1].getTime();

        long bstatr = b[0].getTime();
        long bend = b[1].getTime();


        if (astatr >= bstatr && astatr < bend && astatr != aend) {
            return true;
        }


        if (astatr <= bstatr && aend > bstatr && bstatr != bend) {
            return true;
        }


        if (astatr == bstatr && aend == bend) {
            return true;
        }


        if ((astatr < bstatr && aend > bend) || (bstatr < astatr && bend > aend)) {
            return true;
        }

        return false;
    }


    public static void main(String[] args) throws ParseException {
        SimpleDateFormat SF = new SimpleDateFormat("yyyy-MM-dd");

        Date[] a = {SF.parse("2017-07-08"), SF.parse("2017-07-09")};
        Date[] b = {SF.parse("2017-07-06"), SF.parse("2017-07-09")};

        System.out.println("您好, 智能的电脑! 请问:");
        byte b1;
        int i;
        Date[] arrayOfDate1;
        for (i = (arrayOfDate1 = a).length, b1 = 0; b1 < i; ) {
            Date date = arrayOfDate1[b1];
            System.out.print(String.valueOf(date.toString()) + " ~  ");
            b1++;
        }

        System.out.println("包含:");
        for (i = (arrayOfDate1 = b).length, b1 = 0; b1 < i; ) {
            Date date = arrayOfDate1[b1];
            System.out.print(String.valueOf(date.toString()) + " ~  ");
            b1++;
        }

        System.out.println("吗?");

        boolean ret = isContain(a, b);
        System.out.println("o(∩_∩)o 哈哈 ~ 我猜是: " + ret);

        ret = isContainEnd(a, b);
        System.out.println("o(∩_∩)o 哈哈 ~ 允许首尾相等 我猜是: " + ret);
    }
}
